package com.zucc.controller;

import com.zucc.controller.req.UserAddReq;
import com.zucc.controller.req.UserLoginReq;
import com.zucc.controller.req.UserModifyReq;
import com.zucc.controller.req.UserSearchReq;
import com.zucc.controller.resp.UserResp;
import com.zucc.service.UserService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-05 8:18 上午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/users")
@Api(tags = "用户管理")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "新增用户")
    @PostMapping
    void add(@RequestBody @Validated UserAddReq req) {
        userService.add(req);
    }

    @ApiOperation(value = "修改用户")
    @PutMapping
    void modify(@RequestBody @Validated UserModifyReq req) {
        userService.modify(req);
    }

    @ApiOperation(value = "删除用户")
    @ApiImplicitParam(paramType = "path", name = "id", value = "用户编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        userService.deleteOne(id);
    }

    @ApiOperation(value = "用户分页")
    @PostMapping("/page")
    PageData<UserResp> page(@RequestBody @Validated UserSearchReq req) {
        return userService.page(req);
    }

    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    UserResp login(@RequestBody @Validated UserLoginReq req) {
        return userService.login(req);
    }
}
